package com.coffee.mybatis;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coffee.core.CoffeeConvert;
import com.coffee.core.CoffeePage;

/**
 * @author: songkui
 * @since: 2022/6/21 18:04
 */
public class PageHandler {


    public static <T> CoffeePage<T> buildCoffeePage(Page<T> page){
        return CoffeePage.of(page.getRecords(), page.getTotal(),  page.getSize(),  page.getCurrent());
    }

    public static <B, E, V> CoffeePage<V> convertCoffeePage(Page<E> page, CoffeeConvert<B, E, V> convert){
        if (null == page){
            return null;
        }
        return CoffeePage.of(convert.entityToVOList(page.getRecords()), page.getTotal(),  page.getSize(),  page.getCurrent());
    }

}
